package com.jinlejia.bbs.logic.message;

import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.jinlejia.bbs.http.utils.BBSConfig;
import com.jinlejia.bbs.http.utils.HttpCallBack;

import static com.jinlejia.bbs.http.utils.HttpUtils.*;

public class MessageIgnoreInviteLogic {
    private Context context;
    public MessageIgnoreInviteLogic(Context context){
        this.context = context;
    }
    private volatile boolean isExecute;
    public void execute(String messageId, final LogicCallBack callBack){
        if (isExecute)return;
        isExecute = true;
        String url = BBSConfig.updateReadStateById;
        url = url.concat(messageId);
        JSONObject json = new JSONObject();
        httpCallForm(url,json).execute(httpCallBack(context, new HttpCallBack() {
            @Override
            public void onError(Exception e) {
                callBack.onResult(false);
                isExecute = false;
            }

            @Override
            public void onResponse(JsonParse parse) {
                boolean result = parse.parse(Boolean.class);
                callBack.onResult(result);
                isExecute = false;
            }

            @Override
            public void onNoResponse(int code) {
                callBack.onResult(false);
                isExecute = false;
            }
        }));
    }

    public interface LogicCallBack{
        void onResult(boolean result);
    }
}
